package com.sunyard.manage.config;

import org.hibernate.validator.HibernateValidator;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.validation.Validation;
import javax.validation.Validator;

/**
 * 使用hibernate的注解进行自定义参数校验
 *
 * @author DUANYUBIN
 * @date 2021-04-16 10:07
 **/
@Configuration
public class ValidConfig {

    @Bean(name = "failFastValidator")
    public Validator failFastValidator() {
        return Validation
                .byProvider(HibernateValidator.class)
                .configure()
                .failFast(true)  //快速失败：只要有1个参数校验不通过，就立即停止校验参数
                .buildValidatorFactory()
                .getValidator();
    }
}
